package netty.inboundhandlerandoutboundhandler;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

/**
 * @author 帅小伙
 * @date 2022/1/21
 * @description
 */
public class MyClientHandler extends SimpleChannelInboundHandler<Long> {


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Long msg) throws Exception {
        System.out.println("从服务器:"+ctx.channel().remoteAddress()+"\n读取到long:"+msg);
    }


    /*
    * 重写channelActive 发送数据
    * */
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("myClient发送数据");
        //ctx.writeAndFlush(123L);
        ctx.writeAndFlush(Unpooled.copiedBuffer("abcdabcdbcadbcad", CharsetUtil.UTF_8));
    }
}
